package com.ruantong.dingtalk.ding.callback.listener;

import com.ruantong.dingtalk.ding.callback.enums.AttendanceEventEnum;
import com.ruantong.dingtalk.ding.callback.listener.event.AttendanceEvent;
import com.ruantong.dingtalk.ding.callback.listener.event.CallbackEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @description:钉钉回调事件监听器
 * @author: jh.chen
 * @time: 2020/11/16 23:22
 */
@Slf4j
@Component
public class CallbackEventListener {

    @EventListener
    @Async
    public void listen(CallbackEvent event) throws Exception {
        if (event instanceof AttendanceEvent) {
            log.info("listening AttendanceEvent now");
            AttendanceEvent attnEvent = (AttendanceEvent) event;
            if (attnEvent.getEventEnum() == AttendanceEventEnum.ATTENDANCE_CHECK_RECORD) {
                //TODO
                log.info(attnEvent.getSource().getClass().getName());
                log.info("AttendanceEvent:", attnEvent.getEventEnum().value());
            }
        }
    }
}
